package com.hue.concurrent.day04;

/*
    死锁现象
    检测死锁的工具：1.jstack  2.jconsole
 */
public class Demo04 {
    public static void main(String[] args) {
        Object a = new Object();
        Object b = new Object();
        new Thread(() -> {
            synchronized (a){
                System.out.println("t1 lock a");
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (b){
                    System.out.println("t1 lock b");
                }
            }
        }).start();

        new Thread(() -> {
            synchronized (b){
                System.out.println("t2 lock b");
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (a){
                    System.out.println("t2 lock a");
                }
            }
        }).start();
    }
}
